<!DOCTYPE html>

<html>
<head>
  <title>Array</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="Array.coffee.html">
                Array.coffee.md
              </a>
            
              
              <a class="source" href="BareObject.coffee.html">
                BareObject.coffee.md
              </a>
            
              
              <a class="source" href="Boolean.coffee.html">
                Boolean.coffee.md
              </a>
            
              
              <a class="source" href="Function.coffee.html">
                Function.coffee.md
              </a>
            
              
              <a class="source" href="Math.coffee.html">
                Math.coffee.md
              </a>
            
              
              <a class="source" href="Maybe.coffee.html">
                Maybe.coffee.md
              </a>
            
              
              <a class="source" href="Nullable.coffee.html">
                Nullable.coffee.md
              </a>
            
              
              <a class="source" href="Number.coffee.html">
                Number.coffee.md
              </a>
            
              
              <a class="source" href="Object.coffee.html">
                Object.coffee.md
              </a>
            
              
              <a class="source" href="Promise.coffee.html">
                Promise.coffee.md
              </a>
            
              
              <a class="source" href="String.coffee.html">
                String.coffee.md
              </a>
            
              
              <a class="source" href="Type.coffee.html">
                Type.coffee.md
              </a>
            
              
              <a class="source" href="header.coffee.html">
                header.coffee.md
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <h1 id="array">Array</h1>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	Array.<span class="hljs-function"><span class="hljs-title">concat</span> = <span class="hljs-params">(arrays...)</span> -&gt;</span> [].concat arrays...
	
	Array.<span class="hljs-function"><span class="hljs-title">map</span> = <span class="hljs-params">(fn)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(arr)</span> -&gt;</span> arr.map fn
			
	Array.<span class="hljs-function"><span class="hljs-title">reduce</span> = <span class="hljs-params">(reduction,initial)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(array)</span> -&gt;</span> array.reduce(reduction,initial <span class="hljs-keyword">or</span> reduction.unit)

	Array.<span class="hljs-function"><span class="hljs-title">zip</span> = <span class="hljs-params">(arrays...)</span> -&gt;</span>
		maxIndex = Math.min ( arr.length-<span class="hljs-number">1</span> <span class="hljs-keyword">for</span> arr <span class="hljs-keyword">in</span> arrays )...
		<span class="hljs-keyword">return</span> [] <span class="hljs-keyword">if</span> maxIndex <span class="hljs-keyword">in</span> [-<span class="hljs-number">1</span>,Infinity]
		( arr[i] <span class="hljs-keyword">for</span> arr <span class="hljs-keyword">in</span> arrays <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> [<span class="hljs-number">0.</span>.maxIndex] )
		
	Array.<span class="hljs-function"><span class="hljs-title">zipWith</span> = <span class="hljs-params">(fn)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(arrays...)</span> -&gt;</span>
		Array.zip<span class="hljs-function"><span class="hljs-params">(arrays...)</span>.<span class="hljs-title">map</span> <span class="hljs-params">(arr)</span> -&gt;</span> fn arr...
	
	Array.<span class="hljs-function"><span class="hljs-title">flatten</span> = <span class="hljs-params">(array=[])</span> -&gt;</span>
		Array.concat ( ( <span class="hljs-keyword">if</span> arr <span class="hljs-keyword">instanceof</span> Array <span class="hljs-keyword">then</span> Array.flatten(arr) <span class="hljs-keyword">else</span> arr ) <span class="hljs-keyword">for</span> arr <span class="hljs-keyword">in</span> array )...
		
	Array.<span class="hljs-function"><span class="hljs-title">equal</span> = <span class="hljs-params">(a,b)</span> -&gt;</span> a.length == b.length <span class="hljs-keyword">and</span> Array.reduce(Boolean.<span class="hljs-keyword">and</span>) Array.zipWith(Value.equal) a, b
	
	<span class="hljs-attribute">Array</span>::<span class="hljs-function"><span class="hljs-title">find</span> = <span class="hljs-params">(predicate)</span> -&gt;</span>
		<span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> <span class="hljs-keyword">this</span>
			<span class="hljs-keyword">return</span> item <span class="hljs-keyword">if</span> predicate.call item, item
			
	<span class="hljs-attribute">Array</span>::<span class="hljs-function"><span class="hljs-title">each</span> = <span class="hljs-params">(fn)</span> -&gt;</span>
		<span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> <span class="hljs-keyword">this</span>
			fn.call item, item</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <h2 id="predicates">Predicates</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	Array.<span class="hljs-function"><span class="hljs-title">hastypes</span> = <span class="hljs-params">(types...)</span> -&gt;</span>
		<span class="hljs-function"><span class="hljs-params">(array=[])</span> -&gt;</span>
			<span class="hljs-keyword">return</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">if</span> types.length == <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> array.length == <span class="hljs-number">0</span>
			types2 = types.slice <span class="hljs-number">0</span>
			array2 = array.slice <span class="hljs-number">0</span>
			value  = <span class="hljs-literal">undefined</span>
			<span class="hljs-keyword">while</span> type = types2.shift()
				<span class="hljs-keyword">if</span> type <span class="hljs-keyword">instanceof</span> Array
					[type] = type
					<span class="hljs-keyword">while</span> array2.length &gt; <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> Object.isa(type) array2[<span class="hljs-number">0</span>]
						array2.shift()
				<span class="hljs-keyword">else</span>
					value = array2.shift()
					<span class="hljs-keyword">return</span> <span class="hljs-literal">false</span> <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> Object.isa(type) value
			<span class="hljs-keyword">return</span> types2.length == <span class="hljs-number">0</span> <span class="hljs-keyword">and</span> array2.length == <span class="hljs-number">0</span>
		
	Array.<span class="hljs-function"><span class="hljs-title">all</span> = <span class="hljs-params">(predicate)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(array)</span> -&gt;</span> Array.reduce<span class="hljs-function"><span class="hljs-params">(Boolean.<span class="hljs-keyword">and</span>)</span> <span class="hljs-title">array</span>.<span class="hljs-title">map</span> <span class="hljs-params">(x)</span> -&gt;</span> predicate.call x, x
	
	<span class="hljs-attribute">Array</span>::<span class="hljs-function"><span class="hljs-title">all</span> = <span class="hljs-params">(predicate)</span> -&gt;</span> Array.all(predicate) <span class="hljs-keyword">this</span>
	
	Array.<span class="hljs-function"><span class="hljs-title">any</span> = <span class="hljs-params">(predicate)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(array)</span> -&gt;</span> Array.reduce<span class="hljs-function"><span class="hljs-params">(Boolean.<span class="hljs-keyword">or</span>)</span> <span class="hljs-title">array</span>.<span class="hljs-title">map</span> <span class="hljs-params">(x)</span> -&gt;</span> predicate.call x, x
	
	<span class="hljs-attribute">Array</span>::<span class="hljs-function"><span class="hljs-title">any</span> = <span class="hljs-params">(predicate)</span> -&gt;</span> Array.any(predicate) <span class="hljs-keyword">this</span>
	
	Array.<span class="hljs-function"><span class="hljs-title">none</span> = <span class="hljs-params">(predicate)</span> -&gt;</span> Array.any(predicate).<span class="hljs-keyword">not</span>()
	
	<span class="hljs-attribute">Array</span>::<span class="hljs-function"><span class="hljs-title">none</span> = <span class="hljs-params">(predicate)</span> -&gt;</span> Array.none(predicate) <span class="hljs-keyword">this</span>	
	
	Array.<span class="hljs-function"><span class="hljs-title">ordered</span> = <span class="hljs-params">(array)</span> -&gt;</span> Array.reduce(Boolean.<span class="hljs-keyword">and</span>) Array.zipWith(Value.lt) array, array[<span class="hljs-number">1.</span>.]
		
	<span class="hljs-attribute">Array</span>::<span class="hljs-function"><span class="hljs-title">ordered</span> = -&gt;</span> Array.ordered <span class="hljs-keyword">this</span></pre></div></div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <h2 id="reductions">Reductions</h2>

            </div>
            
            <div class="content"><div class='highlight'><pre>	
	Array.<span class="hljs-function"><span class="hljs-title">count</span> = <span class="hljs-params">(predicate=Boolean.True)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(acc=<span class="hljs-number">0</span>,value)</span> -&gt;</span> acc + <span class="hljs-keyword">if</span> predicate.call(value,value) <span class="hljs-keyword">then</span> <span class="hljs-number">1</span> <span class="hljs-keyword">else</span> <span class="hljs-number">0</span>
	Array.count.unit = <span class="hljs-number">0</span>
	
	<span class="hljs-attribute">Array</span>::<span class="hljs-function"><span class="hljs-title">count</span> = <span class="hljs-params">(predicate)</span> -&gt;</span> <span class="hljs-property">@reduce</span> Array.count(predicate), <span class="hljs-number">0</span>
	
	Array.<span class="hljs-function"><span class="hljs-title">contains</span> = <span class="hljs-params">(predicate=Boolean.True)</span> -&gt;</span> <span class="hljs-function"><span class="hljs-params">(acc=<span class="hljs-literal">false</span>,value)</span> -&gt;</span> acc <span class="hljs-keyword">or</span> predicate.call(value,value)
	Array.contains.unit = <span class="hljs-literal">false</span>
	
	<span class="hljs-attribute">Array</span>::<span class="hljs-function"><span class="hljs-title">contains</span> = <span class="hljs-params">(predicate)</span> -&gt;</span> <span class="hljs-property">@reduce</span> Array.contains(predicate), <span class="hljs-literal">false</span></pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
